<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>统计⼀个字符串中某个字符出现的次数</title>
</head>

<body>

</body>

</html>
<script>
    var ary = prompt('请输入英文字母，数字');

    var obj = {};
    var i = 0;
    ary1 = ary.toLocaleLowerCase();     //把字母转换成小写

    for (i = 0; i < ary1.length; i++) {
        key = ary1[i];
        if (obj[key]) {
            //对象中有这个字母
            obj[key]++;
        }
        else {
            //对象中没有这个字母,把字母加到对象中
            obj[key] = 1;
        }
    }

    for (var key in obj) { //遍历这个对象
        console.log(key + "这个字符出现了" + obj[key] + "次");
    }
</script>